package cn.com.hhrcw.es.mapstruct;

import cn.com.hhrcw.entity.EnInfo;
import cn.com.hhrcw.entity.OpJob;
import cn.com.hhrcw.es.entity.JobPositionDocument;
import cn.com.hhrcw.es.entity.RecruitmentPositionDocument;
import cn.com.hhrcw.es.entity.UniversityDocument;
import cn.com.hhrcw.es.entity.UniversitySpecialityDocument;
import cn.com.hhrcw.position.entity.RecruitmentPosition;
import cn.hutool.core.util.StrUtil;
import org.jeecg.common.system.vo.DictModel;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;

import java.util.List;

/**
 * @author lixingxing
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE, imports = {StrUtil.class})
public interface ElasticsearchConvert {

    /**
     * RecruitmentPosition 转 RecruitmentPositionDocument
     *
     * @param entity
     * @return
     */
    @Mapping(target = "title", source = "name")
    RecruitmentPositionDocument toPosition(RecruitmentPosition entity);

    /**
     * RecruitmentPosition 转 RecruitmentPositionDocument
     *
     * @param entity
     * @return
     */
    List<RecruitmentPositionDocument> toPosition(List<RecruitmentPosition> entity);

    /**
     * DictModel 转 UniversityDocument
     *
     * @param entity
     * @return
     */
    @Mapping(target = "title", source = "text")
    @Mapping(target = "id", source = "value")
    UniversityDocument toUniversity(DictModel entity);

    /**
     * DictModel 转 UniversityDocument
     *
     * @param entity
     * @return
     */
    List<UniversityDocument> toUniversity(List<DictModel> entity);

    /**
     * DictModel 转 UniversitySpecialityDocument
     *
     * @param entity
     * @return
     */
    @Mapping(target = "title", source = "text")
    @Mapping(target = "id", source = "value")
    UniversitySpecialityDocument toSpeciality(DictModel entity);

    /**
     * DictModel 转 UniversitySpecialityDocument
     *
     * @param entity
     * @return
     */
    List<UniversitySpecialityDocument> toSpeciality(List<DictModel> entity);

    /**
     * 组装招聘岗位数据
     *
     * @param job
     * @param info
     * @return
     */
    @Mapping(target = "id", source = "job.id")
    @Mapping(target = "title",source = "job.jobName")
    @Mapping(target = "companyId",source = "info.id")
    @Mapping(target = "companyLogo",source = "info.enLogo")
    @Mapping(target = "sessionId",source = "job.bsId")
    @Mapping(target = "companyName",source = "info.enName")
//    @Mapping(target = "publishTime", expression = "java(job.getUpdateTime() != null ? job.getUpdateTime() : job.getCreateTime())")
    @Mapping(target = "publishTime", source = "job.createTime")
    @Mapping(target = "companyBenefits",expression = "java(StrUtil.split(info.getOtherWelfare(),','))")
    @Mapping(target = "recommendNo",expression = "java(job.getRecommendNo() == null ? 0 : job.getRecommendNo())")
    @Mapping(target = "refreshNo",expression = "java(cn.com.hhrcw.es.util.JobRefreshNoUtil.createIndexRefreshNo(job.getRecommendNo(),job.getRefreshNo(),job.getCreateTime()))")
    JobPositionDocument toJobPosition(OpJob job, EnInfo info);
}
